import dotenv from 'dotenv';

// Load environment variables
dotenv.config();

export default {
  app: {
    port: parseInt(process.env.PORT || '4000'),
    env: process.env.NODE_ENV || 'development'
  },
  
  database: {
    url: process.env.DATABASE_URL || 'postgresql://chainwatch:password@localhost:5432/chainwatch',
    host: process.env.DB_HOST || 'localhost',
    port: parseInt(process.env.DB_PORT || '5432'),
    database: process.env.DB_NAME || 'chainwatch',
    username: process.env.DB_USER || 'chainwatch',
    password: process.env.DB_PASSWORD || 'password'
  },
  
  redis: {
    url: process.env.REDIS_URL || 'redis://localhost:6379',
    host: process.env.REDIS_HOST || 'localhost',
    port: parseInt(process.env.REDIS_PORT || '6379')
  },
  
  chains: {
    ethereum: {
      name: 'Ethereum',
      rpcUrl: process.env.ETHEREUM_RPC_URL || 'https://ethereum.publicnode.com',
      wssUrl: process.env.ETHEREUM_WSS_URL || 'wss://1rpc.io/eth',
      minValueUSD: parseInt(process.env.ETHEREUM_MIN_VALUE_USD || '5000'),
      blockTime: 12000, // 12 seconds
      // 备用RPC端点
      fallbackRpcUrls: [
        'https://ethereum.publicnode.com',
        'https://ethereum-rpc.publicnode.com',
        'https://eth.llamarpc.com',
        'https://rpc.ankr.com/eth',
        'https://ethereum.blockpi.network/v1/rpc/public',
        'https://eth-mainnet.public.blastapi.io'
      ]
    },
    bsc: {
      name: 'Binance Smart Chain',
      rpcUrl: process.env.BSC_RPC_URL || 'https://bsc-dataseed.binance.org/',
      wssUrl: process.env.BSC_WSS_URL,
      minValueUSD: parseInt(process.env.BSC_MIN_VALUE_USD || '5000'),
      blockTime: 3000 // 3 seconds
    },
    bitcoin: {
      name: 'Bitcoin',
      rpcUrl: process.env.BITCOIN_RPC_URL || 'https://bitcoin.publicnode.com',
      minValueUSD: parseInt(process.env.BITCOIN_MIN_VALUE_USD || '100000'),
      blockTime: 600000 // 10 minutes
    },
    base: {
      name: 'Base',
      rpcUrl: process.env.BASE_RPC_URL || 'https://mainnet.base.org',
      wssUrl: process.env.BASE_WSS_URL,
      minValueUSD: parseInt(process.env.BASE_MIN_VALUE_USD || '10000'),
      blockTime: 2000 // 2 seconds
    },
    polygon: {
      name: 'Polygon',
      rpcUrl: process.env.POLYGON_RPC_URL || 'https://polygon-rpc.com/',
      wssUrl: process.env.POLYGON_WSS_URL,
      minValueUSD: parseInt(process.env.POLYGON_MIN_VALUE_USD || '20000'),
      blockTime: 2000 // 2 seconds
    },
    solana: {
      name: 'Solana',
      rpcUrl: process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com',
      wssUrl: process.env.SOLANA_WSS_URL,
      minValueUSD: parseInt(process.env.SOLANA_MIN_VALUE_USD || '25000'),
      blockTime: 400 // 400ms
    }
  },
  
  monitoring: {
    minTransactionValueUSD: parseInt(process.env.MIN_TRANSACTION_VALUE_USD || '5000'),
    whaleThresholdUSD: parseInt(process.env.WHALE_THRESHOLD_USD || '1000000'),
    highRiskThreshold: parseInt(process.env.HIGH_RISK_THRESHOLD || '70'),
    batchSize: parseInt(process.env.BATCH_SIZE || '100'),
    requestDelay: parseInt(process.env.REQUEST_DELAY || '100'),
    defaultMinValue: parseInt(process.env.DEFAULT_MIN_VALUE || '5000'),
    blockCheckInterval: parseInt(process.env.BLOCK_CHECK_INTERVAL || '5000'),
    maxTransactionsPerBlock: parseInt(process.env.MAX_TRANSACTIONS_PER_BLOCK || '50')
  },
  
  alerts: {
    email: {
      service: process.env.EMAIL_SERVICE || 'gmail',
      user: process.env.EMAIL_USER || '',
      password: process.env.EMAIL_PASSWORD || '',
      from: process.env.EMAIL_FROM || process.env.EMAIL_USER
    },
    webhook: {
      url: process.env.WEBHOOK_URL || '',
      timeout: parseInt(process.env.WEBHOOK_TIMEOUT || '5000')
    },
    rateLimit: parseInt(process.env.ALERT_RATE_LIMIT || '10')
  },
  
  api: {
    rateLimit: parseInt(process.env.API_RATE_LIMIT || '100'),
    analysisRateLimit: parseInt(process.env.ANALYSIS_RATE_LIMIT || '10'),
    timeout: parseInt(process.env.API_TIMEOUT || '30000')
  },
  
  security: {
    jwtSecret: process.env.JWT_SECRET || 'your-jwt-secret-key',
    encryptionKey: process.env.ENCRYPTION_KEY || 'your-encryption-key',
    corsOrigin: process.env.CORS_ORIGIN || '*'
  },
  
  logging: {
    level: process.env.LOG_LEVEL || 'info',
    file: process.env.LOG_FILE || 'logs/app.log'
  },
  
  externalApis: {
    arkham: {
      apiKey: process.env.ARKHAM_API_KEY || '',
      baseUrl: 'https://api.arkhamintelligence.com'
    },
    chainalysis: {
      apiKey: process.env.CHAINALYSIS_API_KEY || '',
      baseUrl: 'https://api.chainalysis.com'
    },
    trmLabs: {
      apiKey: process.env.TRM_LABS_API_KEY || '',
      baseUrl: 'https://api.trmlabs.com'
    }
  },
  
  // Next.js specific configuration
  nextjs: {
    websocketPort: parseInt(process.env.WEBSOCKET_PORT || '8080'),
    apiBasePath: '/api',
    staticGeneration: process.env.NODE_ENV === 'production'
  }
}; 